/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function listJSON(a) {
    var treeJSON = ""; 
    $.ajax({
      cache: false,
      url: "/demo/archetype/listJSON",
      data:{archetypes:a},
      success: function(msg) {
          
          treeJSON = msg;          
          /*
          var str = JSON.stringify(treeJSON);          
          $("#divArquetipoPrueba").html(str);
          */
         
         $("#divArquetipo").jstree({
               "json_data" : {
                       "data": [treeJSON]                     
                },                            
                "themes" : {
	            "theme" : "default",                     
	            "dots" : true,
	            "icons" : true
                },
                "types" : {                    
                    "types" : {
                        "action" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/action.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },
                        "cluster" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/cluster.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },
                        "composition" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/composition.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },
                        "count" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/count.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },
                        "datetime" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/datetime.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },
                        "duration" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/duration.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },
                        "element" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/element.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },
                        "evaluation" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/evaluation.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },                        
                        "instruction" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/instruction.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },                         
                        "observation" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/observation.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },                            
                        "ordinal" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/ordinal.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },                          
                        "quantity" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/quantity.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        }, 
                        "section" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/section.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },                                                 
                        "slot_cluster" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/slot_cluster.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },
                        "structure" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/structure.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },                         
                        "text" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/text.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        }, 
                        "truefalse" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/truefalse.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        },
                        "default" : {
                            "icon" : {
                                "image" : "/demo/js/jstree/themes/default/icons/default.png"
                            },
                            "hover_node" : true,
                            "select_node" : function () {return true;}
                        } 
                    },
                    "use_data": true 
		},
                "plugins" : [ "themes", "json_data", "ui", "types" ],
                "core":{"animation":0}
         })
         .bind("select_node.jstree", function (event, data) {	            
	            var id = data.rslt.obj.attr("id");                    
                    alert("id: " + id + " path: " + data.rslt.obj.data('path') + " tipo: " + data.rslt.obj.data('tipo'));                    
         }); 
      },    
      error: function(msg) {           
           //$("#divArquetipoPrueba").html(msg.responseText);
      }     
    });	
}